package ar.com.tallerdos.smartdinner.util;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import ar.com.tallerdos.smartdinner.R;

public class DialogHandler {
    public Runnable ans_true = null;
    public Runnable ans_false = null;

    // Dialog. --------------------------------------------------------------
    
    public boolean Confirm(Activity act, String Title, String ConfirmText, Runnable aProcedure,
	    Runnable bProcedure) {
	String aceptar = act.getResources().getString(R.string.aceptar);
	String cancelar = act.getResources().getString(R.string.cancelar);
	return Confirm(act, Title, ConfirmText,
		cancelar, aceptar, aProcedure, bProcedure);
    }

    public boolean Confirm(Activity act, String Title, String ConfirmText,
	    String CancelBtn, String OkBtn, Runnable aProcedure,
	    Runnable bProcedure) {
	ans_true = aProcedure;
	ans_false = bProcedure;
	AlertDialog dialog = new AlertDialog.Builder(act).create();
	dialog.setTitle(Title);
	dialog.setMessage(ConfirmText);
	dialog.setCancelable(false);
	dialog.setButton(DialogInterface.BUTTON_POSITIVE, OkBtn,
		new DialogInterface.OnClickListener() {
		    public void onClick(DialogInterface dialog, int buttonId) {
			ans_true.run();
		    }
		});
	dialog.setButton(DialogInterface.BUTTON_NEGATIVE, CancelBtn,
		new DialogInterface.OnClickListener() {
		    public void onClick(DialogInterface dialog, int buttonId) {
			ans_false.run();
		    }
		});
	dialog.setIcon(android.R.drawable.ic_dialog_alert);
	dialog.show();
	return true;
    }
}
